$("#doSubmit").click(function(){
	awd.doSubmit();
});

$("#getsmscode").click(function() {
    awd.sendCode();
});


var awd = {
	flog:false,
	doSubmit:function(){
		this.check();
		if(this.flog){
			$.post(
				"/withdrawals/addWithdrawalsLogHandle",
				{
					num:$("#num").val(),
					seccode:$("#seccode").val(),
					smscode:$("#smscode").val(),
					typeid:$("#typeid").val(),
					receivedid:$("#receivedid").find("option:selected").val()
				},
				function(reg){
					if(reg.status == "success"){
						layer.msg(reg.data,{icon:1});
						setTimeout(function(){
							window.location.href="/withdrawals"
						},1500);
					}else{
						layer.msg(reg.data,{icon:2});
					}
				}
			);
		}
	},
	check:function(){
		if($("#num").val().length<=0){
			layer.tips("提现不能为空或者0","#num");
			$("#num").focus();
		}else if($("#seccode").val().length < 6){
			layer.tips("安全密码不能少于6位","#seccode");
			$("#seccode").focus();
		}else if($("#smscode").val().length <= 0){
			layer.tips("验证码不能为空","#smscode");
			$("#smscode").focus();
		}else{
			this.flog = true;
		}
	},
	sendCode: function() {
        var that = this;
            $.get(
                "/withdrawals/getSmsCode", 
                function(reg) {
                    if (reg.status == "success") {
                        layer.msg(reg.data, {
                            icon: 1
                        })
                        that.disableButton();
                    } else if (reg.status == "failed") {
                        //that.isStartCheckCode = true;//------------
                        layer.msg(reg.data, {
                            icon: 2
                        })
                    }
                }
            );
    },
	disableButton: function() {
        $("#getsmscode").attr('disabled', "disabled");
        var timestamp = new Date().getTime(); //得到当前时间戳  毫秒级别
        localStorage.codeTime3 = timestamp;
        this.recoveryButton();
    },
    recoveryButton: function(ts) {
        console.log(1);
        var that = this;
        var timestamp3 = new Date().getTime();
        ts = timestamp3 - parseInt(localStorage.codeTime3);
        $("#getsmscode").attr('disabled', "disabled");
        if (ts < 60000) {
            $("#getsmscode").text(60 - parseInt(ts / 1000) + "S");
            setTimeout(function() {
                --ts;
                that.recoveryButton(ts);
            }, 1000);

        } else {
            $("#getsmscode").removeAttr('disabled');
            $("#getsmscode").blur();
            $("#getsmscode").text("获取短信验证码");
        }
    }
}
awd.recoveryButton();